<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@include file="../common/head.jsp"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<script language="javascript" src="js/jquery-1.8.3.min.js"></script>
<script>
    $(function(){
        $("#userForm").submit(function(){
            var myFlag=checkUserCode($("#userCode")[0]);
            return myFlag;
        });
        $("[name=\"userCode\"]").blur(function () {
            checkUserCode(this);
        });
    });
    function checkUserCode(userCodeObject){
            //alert(this.value);
            var msg="请输入用户编码";
            var flag=false;
            if(userCodeObject.value!="") {
                $.ajax({
                    async: false,
                    data: {"userCode": userCodeObject.value},
                    url: "user/checkUserCode",
                    success: function (userCount) {
                        if (userCount == 1) {
                            msg = "编码已存在，请重新输入";
                            flag=false;
                        } else if (userCount == 0) {
                            msg = "编码可以使用";
                            flag=true;
                        }
                    }
                });
            }
            userCodeObject.nextElementSibling.innerHTML=msg;
            return flag;
    }
</script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面 >> 用户添加页面</span>
    </div>
    <div class="providerAdd">
        <form:form modelAttribute="user" enctype="multipart/form-data" id="userForm" name="userForm" method="post" action="user/add">
            <!--div的class 为error是验证错误，ok是验证成功-->
            <div>
                <label for="userCode">用户编码：</label>
                <form:input type="text" path="userCode" id="userCode"/>
                <!-- 放置提示信息 -->
                <font color="red"></font>
            </div>
            <div>
                <label for="userName">用户姓名：</label>
                <form:input type="text" path="userName" id="userName"/>
                <font color="red"><form:errors path="userName" /></font>
            </div>
            <div>
                <label for="userPassword">用户密码：</label>
                <form:password path="userPassword" id="userPassword"/>
                <font color="red"><form:errors path="userPassword"/> </font>
            </div>
            <div>
                <label for="ruserPassword">确认密码：</label>
                <input type="password" name="ruserPassword" id="ruserPassword">
                <font color="red"></font>
            </div>
            <div>
                <label >用户性别：</label>
                <form:radiobutton path="gender" value="1"/>男
                <form:radiobutton path="gender" value="2"/>女
                <font color="red"><form:errors path="gender"/> </font>
            </div>
            <div>
                <label for="birthday">出生日期：</label>
                <form:input Class="Wdate" id="birthday" path="birthday"/>
                <font color="red"></font>
            </div>
            <div>
                <label for="phone">用户电话：</label>
                <form:input path="phone" id="phone"/>
                <font color="red"></font>
            </div>
            <div>
                <label for="address">用户地址：</label>
                <form:input path="address" id="address" size="30"/>
            </div>
            <div>
                <label >用户角色：</label>
                <!-- 列出所有的角色分类 -->
                <form:select path="role.roleId" id="userRole">
                    <c:forEach items="${requestScope.roleList}" var="role">
                        <form:option value="${role.roleId}">${role.roleName}</form:option>
                    </c:forEach>
                </form:select>
                <font color="red"></font>
            </div>
            <div>
                <label for="pic">用户照片：</label>
                一寸照：<input type="file" name="pic" id="pic" size="30"/><br/>
                证件照：<input type="file" name="pic"/>
            </div>
            <div class="providerAddBtn">
                <form:button name="add" id="add" >保存</form:button>
                <input type="button" id="back" onclick="window.history.back()" name="back" value="返回" >
            </div>
        </form:form>
    </div>
</div>
</section>
<%@include file="../common/foot.jsp" %>
